Skip to content

Bubble sort lua #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 3, 2018
Merged

Conversation

Gorzoid
Copy link
Contributor

@Gorzoid Gorzoid commented Oct 1, 2018

Lua is pretty empty so I will probably start filling it up for hacktoberfest

@leios leios added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 1, 2018
Pretty sure I got it right, should probably run the book to check
Forgot lua could do this derp.
Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I addressed a few minor things

@@ -22,6 +22,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
[import:4-9, lang:"python"](code/python/bubblesort.py)
{% sample lang="m" %}
[import:1-13, lang:"matlab"](code/matlab/bubblesort.m)
{% sample lang="lua" %}
[import:1-19, lang="lua"](code/lua/bubble_sort.lua)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here import only the function, and later import the whole file

@@ -0,0 +1,17 @@

function bubble_sort(arr)
for i = 1,#arr do
Copy link
Member

@jiegillet jiegillet Oct 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only need to be 1,#arr-1 since for n elements you only need to do n-1 passes.


bubble_sort(arr)

print(("Sorted array: {%s}"):format(table.concat(arr,", ")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need a newline after the last line

@@ -0,0 +1,17 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't open with an empty line

@jiegillet jiegillet self-assigned this Oct 2, 2018
Fixed bubble_sort.md and small changes to code
Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks fine now, but when I run your code here the array doesn't get sorted. I don't know why.

@@ -77,6 +79,8 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
[import, lang:"python"](code/python/bubblesort.py)
{% sample lang="m" %}
[import, lang:"matlab"](code/matlab/bubblesort.m)
{% sample lang="lua" %}
[import:1-17, lang="lua"](code/lua/bubble_sort.lua)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply write [import, lang=...] is you want to import the whole file.

Not necessary when importing entire file
Probably should have tested before pushing
@Gorzoid
Copy link
Contributor Author

Gorzoid commented Oct 3, 2018

Issue was with swap code in the wrong order, checked it and it ran fine this time

@jiegillet
Copy link
Member

jiegillet commented Oct 3, 2018

"Probably should have tested before pushing" hahaha, yup :)
All good now, well done!

@jiegillet jiegillet merged commit 76efd85 into algorithm-archivists:master Oct 3, 2018
kenpower pushed a commit to kenpower/algorithm-archive that referenced this pull request Oct 22, 2018
* Added Bubble Sort in Lua

* Added test case

Stole numbers from C code /:

* Moved files cus derp

* Added Lua entry to md file

Pretty sure I got it right, should probably run the book to check

* Use tuple style swap

Forgot lua could do this derp.

* Addressing problems

Fixed bubble_sort.md and small changes to code

* Removed unnecessary line specification

Not necessary when importing entire file

* Swap code broken

Probably should have tested before pushing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants